<template>
  <div class="warpper">
    <div class="hasspread" @click="handleClick">
      <i :class="isCollapse ? 'el-icon-s-fold' : 'el-icon-s-unfold'"></i>
      <!-- 面包屑 -->
      <div class="crumbs">
        <span>您当前的位置:</span>
        <el-breadcrumb separator="/">
          <el-breadcrumb-item
            v-for="item in routeData"
            :key="item.path"
            :to="{ path: item.path }"
          >
            <i :class="`iconfont ${item.icon}`"></i>
            <span style="color: #fff; font-size: 14px">
              {{ item.title }}
            </span>
          </el-breadcrumb-item>
        </el-breadcrumb>
      </div>
    </div>
    <!-- 用户信息 -->
    <div class="userinfo">
      <!-- 头像 -->
      <!-- 用户昵称 -->
      <div class="user">
        <span class="el-icon-s-custom"></span>
        管理员,你好
      </div>
      <!-- 退出登录 -->
      <div class="logout" @click="logout">
        <el-tooltip
          class="item"
          effect="dark"
          content="退出登录"
          placement="bottom"
        >
          <span class="el-icon-switch-button"></span>
        </el-tooltip>
      </div>
    </div>
  </div>
</template>
<script>
import { mapState } from "vuex";
export default {
  props: {},
  components: {},
  data() {
    return {
      routeData: "", // 路由数据
    };
  },
  methods: {
    handleClick() {
      let { isCollapse } = this.$store.state;
      this.$store.commit("setCollapse", !isCollapse);
    },
    // 退出登录
    logout() {
      this.$confirm("是否退出当前登录", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$router.push("/login");
        })
        .catch(() => {});
    },
    getRouterPath() {
      let matched = this.$route.matched.filter(
        (item) => item && item.meta && item.meta.title
      );

      let first = matched[0];

      let temp = matched.map((item) => {
        if (item.path != "/home") {
          return {
            path: item.path,
            title: item.meta.title,
            icon: item.meta.icon,
          };
        } else {
          return {};
        }
      });
      this.routeData = [{ path: "/home", title: "首页", icon: "" }, ...temp];
    },
  },
  mounted() {
    this.getRouterPath();
  },
  watch: {
    "$route": {
      deep: true,
      immediate: true,
      handler() {
        this.getRouterPath();
      },
    },
  },
  computed: {
    ...mapState(["isCollapse"]),
  },
  filters: {},
};
</script>
<style lang="scss" scoped>
.warpper {
  height: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;

  .hasspread {
    // width: 120px;
    display: flex;
    align-items: center;
    i {
      font-size: 26px;
      color: #fff;
    }

    .crumbs {
      height: 100%;
      display: flex;
      align-items: center;
      margin-left: 20px;
      color: #fff;
      & > span {
        margin-right: 20px;
      }
      .el-breadcrumb {
        line-height: 60px;
      }
    }
  }
  .userinfo {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    .user,
    .logout {
      margin: 0 20px;
      span {
        font-size: 20px;
      }
    }
  }
}
</style>
